#!/usr/bin/env python
#coding: utf8


__author__ = 'Исаков Владислав'
__project_name__ = 'isakov-selenium-python'
__date__ = '08.04.14'

import time


def successful_search(driver, l_search):
    search_input = driver.find_element_by_xpath(".//*[@id='q']")
    assert search_input.is_displayed() & search_input.is_enabled()
    search_word = u"тестовый фильм"
    search_input.send_keys(search_word)
    time.sleep(1)

    i = 0
    l = l_search
    try:
        while i < l:
            el_name = driver.find_element_by_xpath(".//*[@id='results']/a[" + str(l) + "]/div/div[2]")
            assert search_word in el_name.text
            l -= 1
        print "Good search! Items are found in the search!"
    except:
        print "False! Items not found!"